﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RzCorportativo.Views
{
    class ButtonItem<T>
    {
        public string Text { get; set; }
        public string OnClientClick { get; set; }
        public string Id { get; set; }
        public string Type { get; set; }
        public string Name { get; set; }
        public string CssClass { get; set; }
        //public Dictionary<string, string> Attributes { get; set; }
        public Func<T, bool> OnCreateValidation { get; set; }
        public Action<T, ButtonItem<T>> OnCreate { get; set; }

        public ButtonItem()
        {
            //this.Attributes = new Dictionary<string, string>();
        }

        public override string ToString()
        {
            return "<input type='" + this.Type + "' id='" + this.Id + "' " + (string.IsNullOrEmpty(this.Name) ? string.Empty : "name='" + this.Name + "' " ) + 
                (string.IsNullOrEmpty(this.OnClientClick) ? string.Empty : "onclick='" + this.OnClientClick + "' ") + (string.IsNullOrEmpty(this.CssClass) ? string.Empty : "class='" + this.CssClass + "' ") +
                (string.IsNullOrEmpty(this.Text) ? string.Empty : "value='" + this.Text + "' ") + 
                "/>";
        }

        public string ToString(T itemValidation)
        {
            if (this.OnCreate != null)
                this.OnCreate(itemValidation, this);
            if (itemValidation != null && this.OnCreateValidation != null)
            {
                if (this.OnCreateValidation(itemValidation))
                    return "<input type='" + this.Type + "' id='" + this.Id + "' " + (string.IsNullOrEmpty(this.Name) ? string.Empty : "name='" + this.Name + "' ") +
                        (string.IsNullOrEmpty(this.OnClientClick) ? string.Empty : "onclick='" + this.OnClientClick + "' ") + (string.IsNullOrEmpty(this.CssClass) ? string.Empty : "class='" + this.CssClass + "' ") +
                        (string.IsNullOrEmpty(this.Text) ? string.Empty : "value='" + this.Text + "' ") +
                        "/>";
                return string.Empty;
            }
            else
            {
                return "<input type='" + this.Type + "' id='" + this.Id + "' " + (string.IsNullOrEmpty(this.Name) ? string.Empty : "name='" + this.Name + "' ") +
                    (string.IsNullOrEmpty(this.OnClientClick) ? string.Empty : "onclick='" + this.OnClientClick + "' ") + (string.IsNullOrEmpty(this.CssClass) ? string.Empty : "class='" + this.CssClass + "' ") +
                    (string.IsNullOrEmpty(this.Text) ? string.Empty : "value='" + this.Text + "' ") +
                    "/>";
            }
        }
    }
}
